package com.flw.eslab.action.admin;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.stereotype.Controller;

import com.flw.eslab.dto.Info_Dto;
import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.service.InfoManager;


@Controller
@Results({
	@Result(name = "tolist", location = "info?jump_url=list", type = "redirect"),
	@Result(name = "toAdd", location = "info?jump_url=add", type = "redirect")})
public class InfoAction extends CommonAction {
	private Info_Dto info_Dto;
	private InfoManager infoManager;
	private PageInfo_Dto pageInfo_Dto;


	public PageInfo_Dto getPageInfo_Dto() {
		return pageInfo_Dto;
	}

	public void setPageInfo_Dto(PageInfo_Dto pageInfo_Dto) {
		this.pageInfo_Dto = pageInfo_Dto;
	}

	public InfoManager getInfoManager() {
		return infoManager;
	}

	public String add() {
		if(infoManager.add(info_Dto.toInfo())){
			session.put("msg", "新闻添加成功");
			return "tolist";
		}
		else{
			session.put("msg", "新闻添加失败，缺少标题");
			return "toAdd";
		}
		
	}
	
	public String delete(){
		if(infoManager.delete(info_Dto.toInfo())){
			session.put("msg", "新闻删除成功");
		}else{
			session.put("msg", "新闻删除失败，找不到该新闻");
		}
		return "tolist";
	}
	public String update(){
		if(infoManager.modify(info_Dto.toInfo())){
			session.put("msg", "新闻修改成功");
		}else{
			session.put("msg", "新闻修改失败，新闻没有标题或找不到该新闻");
		}
		return "tolist";
	}

	public String load() {
		setPageInfo_Dto(infoManager.load(pageInfo_Dto));
		session.put("pageInfo_Dto", pageInfo_Dto);
		return "success";
	}

	/*--------------------------------*/
	public void setInfo_Dto(Info_Dto info_Dto) {
		this.info_Dto = info_Dto;
	}

	public Info_Dto getInfo_Dto() {
		return info_Dto;
	}

	/*--------------------------------*/
	@Resource
	public void setInfoManager(InfoManager infoManager) {
		this.infoManager = infoManager;
	}
}
